package com.hc.bean;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class Order implements Serializable{
    private Integer orderId;
    private Integer userId;
    private Double totalMoney;
    private String orderDate;
    private String orderFinishDate;
    private Integer orderStatus;
    
    private List<OrderDetail> orderDetailList;  //订单详情
    private User user;  //订单用户

    public Double getTotalMoney() {
        /*totalMoney使用的是包装类 默认值是null 为了防止后面计算总价运算时出现空指针异常,需要给一个初始值*/
        totalMoney=0D;
        if(orderDetailList.size()>0){
            for (OrderDetail orderDetail : orderDetailList) {
                totalMoney+=orderDetail.getPurchaseNum()*orderDetail.getPurchasePrice();
//                System.out.println(orderDetail);
            }
        }
        return totalMoney;
    }
}
